Added api_key option to UserLocationAgent (#1613)

* Added `api_key` option to UserLocationAgent

The `api_key` is used on the summary page of the UserLocationAgent
as well as the event detail page to display a location on a Google
Map which requires an API key. Closes #1612

* added link to Google API key documentation

Sascha Hagedorn 7 years ago
parent
commit
d627a18f6d

+ 3 - 0
app/models/agents/user_location_agent.rb

@@ -14,6 +14,8 @@ module Agents
14 14
       If you want to only keep more precise locations, set `max_accuracy` to the upper bound, in meters. The default name for this field is `accuracy`, but you can change this by setting a value for `accuracy_field`.
15 15
 
16 16
       If you want to require a certain distance traveled, set `min_distance` to the minimum distance, in meters. Note that GPS readings and the measurement itself aren't exact, so don't rely on this for precision filtering.
17
+
18
+      To view the locations on a map, set `api_key` to your [Google Maps JavaScript API key](https://developers.google.com/maps/documentation/javascript/get-api-key#key).
17 19
     MD
18 20
     end
19 21
 
@@ -42,6 +44,7 @@ module Agents
42 44
         'secret' => SecureRandom.hex(7),
43 45
         'max_accuracy' => '',
44 46
         'min_distance' => '',
47
+        'api_key' => '',
45 48
       }
46 49
     end
47 50
 

+ 1 - 1
app/views/agents/agent_views/user_location_agent/_show.html.erb

@@ -1,5 +1,5 @@
1 1
 <% content_for :head do -%>
2
-<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?sensor=false" %>
2
+<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=#{@agent.options[:api_key]}" %>
3 3
 <%= javascript_include_tag "map_marker" %>
4 4
 <% end -%>
5 5
 

+ 1 - 1
app/views/events/show.html.erb

@@ -20,7 +20,7 @@
20 20
 
21 21
       <% if @event.lat && @event.lng %>
22 22
         <% content_for :head do -%>
23
-<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?sensor=false" %>
23
+<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=#{@event.agent.options[:api_key]}" %>
24 24
 <%= javascript_include_tag "map_marker" %>
25 25
         <% end -%>
26 26
 

+ 2 - 1
spec/models/agents/user_location_agent_spec.rb

@@ -6,7 +6,8 @@ describe Agents::UserLocationAgent do
6 6
                                   :name => 'something',
7 7
                                   :options => { :secret => 'my_secret',
8 8
                                     :max_accuracy => '50',
9
-                                    :min_distance => '50' })
9
+                                    :min_distance => '50',
10
+                                    :api_key => 'api_key' })
10 11
     @agent.save!
11 12
   end
12 13